package com.young.monitor.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @Author: Young
 * @CreateTime: 2025-01-14
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("file")
public class FileController {

    @GetMapping("/createFile/{fileName}")
    public boolean createFile(@PathVariable("fileName") String fileName) {
        // 指定目录和文件名
        String directory = "F:\\test";

        // 创建Path对象
        Path path = Paths.get(directory, fileName);

        try {
            // 创建文件
            Files.createFile(path);
            System.out.println("文件创建成功: " + path.toString());
            return true;
        } catch (IOException e) {
            System.err.println("文件创建失败: " + e.getMessage());
        }
        return false;
    }
}
